define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'filetable/index' + location.search,
                    
                    // showToggle:false,
                    // showColumns:false,
                    // showExport:false,
                    add_url: 'filetable/add',
                    edit_url: 'filetable/edit',
                    del_url: 'filetable/del',
                 	upload_url: 'filetable/upload',
                    multi_url: 'filetable/multi',
                    import_url: 'filetable/import',
                    table: 'filetable',
                }
            });

            var table = $("#table");
            var ids = Table.api.selectedids(table);
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                commonSearch:true,
                searchFormVisible: true,
                showToggle:false,
                showColumns:false,
                // searchFormTemplate:'categorytpl',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),operate: false},
                        {field: 'fname', title: __('Fname'), operate: 'LIKE'},
                        {field: 'fpath', title: __('Fpath'), operate: false},
                        {field: 'fdepartment', title: __('Fdepartment')},
                        {field: 'createdate', title: __('Createdate')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                        buttons: [{
									name: 'download',
									title:__('Download'),
									text: '下载',
									icon: 'fa fa-cloud-download',
									classname: 'btn btn-xs btn-info',
									url: 'filetable/upload?ids='+ids,
								  }],
                        formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            
            // $(document).on("click", ".btn-theWeek", function () {
            //     console.log('本周')
            //     console.log($("input[name='year']").val());

            //     var options = table.bootstrapTable('getOptions');
            //     options.pageNumber = 1;
            //     options.queryParams = function (params) {
            //         params.ids = $("input[name='year']").val(); // 值
            //         console.log(params);
            //         return params;
            //     };
            //     table.bootstrapTable('refresh', {});
            //     return false;
            // })
        },
        upload: function () {
            Controller.api.bindevent();
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
